using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.ObjectBuilder;
using Microsoft.Practices.CompositeUI;

namespace Jbe.CABExtension.WPF
{
    /// <summary>
    /// A <see cref="BuilderStrategy"/> that adds services that are needed by Windows Forms 
    /// applications with WPF support into the <see cref="WorkItem"/>.
    /// </summary>
    public class WPFFormServiceStrategy : BuilderStrategy
    {
        public override object BuildUp(IBuilderContext context, Type t, object existing, string id)
        {
            WorkItem workItem = existing as WorkItem;

            if (workItem != null &&
                workItem.Services.ContainsLocal(typeof(IUIElementActivationService)) == false)
            {
                workItem.Services.Add<IUIElementActivationService>(new UIElementActivationService());
            }

            return base.BuildUp(context, t, existing, id);
        }
    }
}
